<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {

	public function index()
	{
		$this->display();
	}

    public function login()
    {	
    	if (IS_POST) {
			$username = I("post.username");
			$password = md5(I("post.password"));
			$code = I("post.verify");

	    	$verify = new \Think\Verify(); 
            if(!$verify->check($code,$id = '')){
            	$arr = array('success'=>false,'msg'=>'验证码错误');
            	$this->ajaxReturn($arr);
            }
			$res = M('user')->where(['username'=>$username,'password'=>$password])->find();
			if ($res) {
    			$arr = array('success'=>true,'msg'=>'登陆成功','url'=>U('index'));
    			$this->ajaxReturn($arr);
			}else {
    			$arr = array('success'=>false,'msg'=>'账号密码错误');
    			$this->ajaxReturn($arr);
			}

    	}else {
    		$this->display();
    	}
    }
    //生成验证码
    public function verify(){
        $verify = new \Think\Verify();
		$verify->fontSize = 16;
		$verify->length   = 3;
		$verify->useNoise = false;
        $verify->entry();
    }
    




}